import pika
import sys
import time
import datetime
#定义一个sleeptime
def sleeptime(hour, min, sec):
    return hour * 3600 + min * 60 + sec
#10秒抓拍一次
second = sleeptime(0, 0, 3)
#send
while 1==1:
    time.sleep(second)
    connection = pika.BlockingConnection(
        pika.ConnectionParameters(host='localhost'))
    channel = connection.channel()

    channel.queue_declare(queue='task_queue', durable=True)#durable设置队列为持久，以防RabbitMQ中止时消息不会丢失

    message =' '.join(sys.argv[1:]) or "Hello world."

    channel.basic_publish(
        exchange='',
        routing_key='task_queue',
        body=message,
        properties=pika.BasicProperties(
            delivery_mode=2,  # make message persistent
        ))
    print(" [x] Sent %r" % message)
    connection.close()